(function() {
   chrome.browserAction.onClicked.addListener(function(tab) {

      var targetTab = 'http://www.wunderlist.com/';

      // Look through all the open tabs find one we can use.
      // url: must be URL pattern like in manifest ex. http://abc.com/* (star is almost mandatory)
      chrome.tabs.query({'url':targetTab + "*"}, function(tabs) {
         if (tabs && tabs.length >= 1) {
            console.log('1. Wunderlist tab found, activating it: ' + tabs[0].id + " - " + tabs[0].url);
            chrome.tabs.update(tabs[0].id, {active:true, highlighted:true});
            console.log("1. Done!");
         } else {
            console.log('2. Wunderlist tab not found, create a new one.');
            chrome.tabs.create({'url':targetTab, active:true});
            console.log("2. Done!");
         };         
      });
   });
}).call(this);